<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <style>
        .btn {
            font-size: 12px;
        }

        .layui-form-checkbox[lay-skin=primary] i {
            top: 5px;
        }
    </style>
</head>
<body>
<title>xianyu -- 任务收退款管理</title>
<form class="layui-form" action="" style="margin-top: 10px">
    <div class="layui-inline" style="margin: 0 0 8px 20px;">
        <label class="layui-form-label" style="width: 95px">起始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="star" placeholder="请选择时间">
        </div>
    </div>
    <div class="layui-inline" style="margin: 0 0 8px 20px;">
        <label class="layui-form-label" style="width: 95px">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="end" placeholder="请选择时间">
        </div>
    </div>
    <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
        <input type="text" name="title" id="title" required lay-verify="required" placeholder="请输入任务名称"
               autocomplete="off"
               class="layui-input">
    </div>
    <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
        <input type="text" name="customName" id="customName" required lay-verify="required" placeholder="请输入客户名称"
               autocomplete="off"
               class="layui-input">
    </div>
    <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
        <select name="cat" id="cat" lay-verify="" style="width: 300">
            <option value="">选择类别</option>
            <option value="1">收款</option>
            <option value="2">退款</option>
        </select>
    </div>
    <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
        <select name="checkStatus" id="checkStatus" lay-verify="" style="width:300">
            <option value="1">未确认</option>
            <option value="">全部</option>

            <option value="2">已确认</option>
        </select>
    </div>
    <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
        <select name="status" id="status" lay-verify="" style="width:300px">
            <option value="">选择状态</option>
            <option value="1">正常</option>
            <option value="2">作废</option>
        </select>
    </div>
    <div style="width: 150px;display: inline-block;margin-left: 20px;">
        <select name="category" id="category" lay-verify="" style="width:300px;margin: 0 0 8px 20px;">
            <option value="">全部任务</option>
            <option value="Common">通用任务</option>
            <option value="Soso">搜搜任务</option>
            <option value="Multiword">多词任务</option>
            <option value="TaoBaoLook">淘宝浏览任务</option>
        </select>
    </div>
    <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
        <select id="customer" name="customer">
            <option value="">全部客户</option>
            <#if customlist?? && ((customlist?size)>0)>
                <#list customlist as list>
                    <#if task??>
                        <option value="${list.customId}"
                                <#if list.customId == task.customer>selected</#if> >${list.name}</option>
                    <#else >
                        <option value="${list.customId}">${list.name}</option>
                    </#if>

                </#list>
            </#if>
        </select>
    </div>
    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">刷新</span>
    <span onclick="confirmAll()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">批量通过</span>
</form>

<table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable" lay-filter="tableFilter">

</table>

</body>
<script type="text/html" id="barDemo">
    {{#  if(d.checkStatus == 1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="confirm">确认通过</a>
    {{#  } else { }}

    {{#  } }}
    {{#  if(d.status == 1){ }}
    <#--<a class="layui-btn layui-btn-xs" lay-event="cancel">作废</a>-->
    {{#  } else { }}

    {{#  } }}

</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.has_deleted== 'False' ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var customer = '';
    var status = '';
    var checkStatus = '1';
    var cat = '';
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var marketId = "";
    var tableIns;
    var ids = "";
    var title = ''
    var form;
    var customName="";
    var table = "tb_finance_record";
    var category = "";
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });
    layui.use('form', function () {
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        tableIns.render({
            elem: '#layTable'
            ,
            totalRow: true

            ,
            toolbar: true
            ,
            url: '/financeRecord/page'
            ,
            method: 'POST' ,limit :1000
            ,
            where: {
                status: status, checkstatus: checkStatus,
                cat: cat, category: category, customId: customer,
                name: title, star: startDate, end: endDate,customName:customName

            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {
                    type: 'checkbox', field: 'id', totalRowText: "合计:"
                }
                , {field: 'amount', title: '金额', width: 100, align: 'center', sort: true, totalRow: true}
                , {
                    field: 'cat', title: '类别', width: 160, align: 'center', sort: true,
                    templet: function (data) {
                        if (data.cat == 1) {
                            return "<div style='color: blue'>收款<div> ";
                        } else {
                            return "<div style='color: red'>退款<div> ";
                        }

                    }
                }
                , {
                    field: 'checkStatus',
                    title: '财务是否确认',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.checkStatus == 1) {
                            return "<div style='color: red'>待确认<div> ";
                        } else {
                            return "<div style='color: blue'>已确认<div> ";
                        }
                    }
                }, {
                    field: 'custom_name',
                    title: '客户名称',
                    width: 120,
                    align: 'center',
                    sort: true
                }, {
                    field: 'taskName',
                    title: '任务名称',
                    width: 160,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'usernickname',
                    title: '财务审核操作人员',
                    width: 160,
                    align: 'center',
                    sort: true
                }
                , {field: 'creatName', title: '创建人', width: 160, align: 'center', sort: true}

                , {
                    field: 'status',
                    title: '状态',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if (data.status == 1) {
                            return "<div style='color: blue'>正常<div> ";
                        } else {
                            return "<div style='color: red'>已作废<div> ";
                        }
                    }
                }
                , {
                    field: 'category',
                    title: '任务类型',
                    width: 160,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        var str = "";
                        switch (data.category) {
                            case "Common":
                                str = "通用任务";
                                break;
                            case "Soso":
                                str = "搜搜任务";
                                break;
                            case "Multiword":
                                str = "多词任务";
                                break;
                            case "TaoBaoLook":
                                str = "淘宝浏览任务";
                                break;
                        }
                        return str;
                    }
                }
                , {field: 'noteA', title: '业务员备注', width: 160, align: 'center', sort: true}
                , {field: 'noteB', title: '财务备注', width: 160, align: 'center', sort: true}
                , {
                    field: 'createTime', title: '创建时间', templet: function (data) {
                        return dateFormat(data.create_time);
                    }, align: 'center', width: 200, sort: true
                }
                , {
                    field: 'modify_time', title: '修改时间', templet: function (data) {
                        return dateFormat(data.modify_time);
                    }, align: 'center', width: 200, sort: true
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 180, align: 'center'}
            ]]
            ,
            page: true
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 'False');
            } else {
                commonenable(this.value, 'true');
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            var  money=0;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    money += dataList[i].amount ;
                }
            }
            layer.msg(money);
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/delete/data",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                if (data.has_deleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                if (data.has_deleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer_show("修改", "/financeRecord/edit?id=" + data.id, "550", "650");
                parent.search();
            } else if (obj.event === 'confirm') {

                layer.prompt({
                    formType: 2,
                    value: '请输入备注',
                    title: '确认通过么?',
                    area: ['300px', '50px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    confirmlList(data.id, value);
                    layer.close(index);
                });


            } /*else if (obj.event === 'cancel') {
                layer.confirm('确认作废么?', function (index) {
                    cancellList(data.id);
                    layer.close(index);
                });
        }*/
        });
    });
    function confirmAll() {
        var idsList = "";
        var checkStatus = tableIns.checkStatus('dataTableId');
        var dataList = checkStatus.data;
        if (dataList != null && dataList.length > 0) {

            for (var i = 0; i < dataList.length; i++) {
                idsList += dataList[i].id + ",";
            }
        }
        if(idsList===""){
            layer.msg("请选择要确认的记录")
            return;
        }
        layer.prompt({
            formType: 2,
            value: '请输入备注',
            title: '确认通过么?',
            area: ['300px', '50px'] //自定义文本域宽高
        }, function (value, index, elem) {
            confirmlList(idsList, value);
            layer.close(index);
        });


        // if (ids != "") {
        //     $.ajax({
        //         url: "/delete/data",
        //         type: 'post',
        //         data: {"table": table, "ids": ids},
        //         async: false,
        //         dataType: "json",
        //         success: function (arg) {
        //             if (arg) {
        //                 layer.msg(arg.message);
        //                 search();
        //             } else {
        //                 layer.msg(arg.message);
        //             }
        //         }
        //     });
        // }
    }
    function cancellList(idlist) {
        $.ajax({
            url: "/financeRecord/cancel",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: {idlist: idlist},    //参数值,键值对
            type: "post",   //请求方式
            beforeSend: function () {
                //请求前的处理
            },
            success: function (req) {
                //请求成功时处理
                if (req.success) {
                    showmsg(req.message);
                    search();
                } else {
                    layer.msg(req.message)
                }
            },
            complete: function () {
                //请求完成的处理
            },
            error: function () {
                //请求出错处理
                layer.msg("请重试！若在失败请联系管理员")
            }
        });
    }

    function search() {
        customer = $("#customer").val();
        category = $("#category").val();
        status = $("#status").val();
        checkStatus = $("#checkStatus").val();
        cat = $("#cat").val();
        startDate = $("#star").val();
        endDate = $("#end").val();
        title = $("#title").val();
        customName=$("#customName").val();
        tableIns.reload('dataTableId', {
            where: {
                status: status, checkstatus: checkStatus,
                cat: cat, category: category, customId: customer,
                name: title, star: startDate, end: endDate,customName:customName

            }
            , page: {
                curr: 1
            }
        });
    }

    $(document).ready(function () {
        $(".gradeEdit").click(function () {
            layer_show("新增", "/financeRecord/edit", "500", "600");
        });

    });


    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/enablebyid",
            type: 'post',
            data: {"table": table, "id": id, "status": status},
            async: false,
            dataType: "json",
            success: function (arg) {
                if (arg) {
                    layer.msg(arg.message);
                    search();
                } else {
                    layer.msg(arg.message);
                }
            }
        });
    }

    function confirmlList(idlist, noteB) {
        $.ajax({
            url: "/financeRecord/confirm",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: {idlist: idlist, note: noteB},    //参数值,键值对
            type: "post",   //请求方式
            beforeSend: function () {
                //请求前的处理
            },
            success: function (req) {
                //请求成功时处理
                if (req.success) {
                    showmsg(req.message);
                    search();
                } else {
                    layer.msg(req.message)
                }
            },
            complete: function () {
                //请求完成的处理
            },
            error: function () {
                //请求出错处理
                layer.msg("请重试！若在失败请联系管理员")
            }
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
